package com.jy.adscm.operation.mscyb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.mscyb.bean.JqbzPartsUseHistory;
import com.jy.adscm.operation.mscyb.bean.JqzzSetting;
import com.jy.adscm.operation.mscyb.mapper.mysql.JqbzPartsUseHistoryMapper;
import com.jy.adscm.operation.mscyb.mapper.mysql.JqzzSettingMapper;
import com.jy.adscm.operation.mscyb.service.JqbzPartsUseHistoryService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-06-03
 */
@Service
public class JqbzPartsUseHistoryServiceImpl extends ServiceImpl<JqbzPartsUseHistoryMapper, JqbzPartsUseHistory> implements JqbzPartsUseHistoryService {
    @Autowired
    JqbzPartsUseHistoryMapper jqbzPartsUseHistoryMapper;
    @Autowired
    JqzzSettingMapper jqzzSettingMapper;
    @Autowired
    JyUserMapper jyUserMapper;
    @Override
    public List<JqbzPartsUseHistory> selectByPid(String pid) {
        Wrapper<JqbzPartsUseHistory> wrapper=new EntityWrapper<>();
        wrapper.eq("pid",pid);
        List<JqbzPartsUseHistory> jqbzPartsUseHistories = jqbzPartsUseHistoryMapper.selectList(wrapper);
        for (JqbzPartsUseHistory jqbzPartsUseHistory : jqbzPartsUseHistories) {
            if (AdscmBaseUtils.getInstance().isNotEmpty(jqbzPartsUseHistory.getRecorderName(),null)){
                JqzzSetting jqzzSetting = jqzzSettingMapper.selectById(jqbzPartsUseHistory.getRecorderName());
                jqbzPartsUseHistory.setRecorderName(jqzzSetting.getName());
            }
            if (AdscmBaseUtils.getInstance().isNotEmpty(jqbzPartsUseHistory.getCreator(),null)){
                JyUser jyUser = jyUserMapper.selectById(jqbzPartsUseHistory.getCreator());
                jqbzPartsUseHistory.setCreatorName(jyUser.getName());
            }

        }
        return jqbzPartsUseHistories;
    }
}
